<?php
defined('_JEXEC') or die;

require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
    include('step2_mobile.php');
    return;
}

//must have required data
$sess=JFactory::getSession();
if(!$sess->get("regs1.data")){
	$app = JFactory::getApplication();
	$app->redirect(JRoute::_('index.php?option=com_users&view=registration'));
}

JHtml::_('behavior.keepalive');
//JHtml::_('behavior.formvalidation');
$db		=JFactory::getDBO();
$params	=JComponentHelper::getParams('com_questions');

$lowcost	=$params->get("price1");$lowtxt="Pakke 1";
$medcost=$params->get("price2");$medtxt="Pakke 2";
$hicost	=$params->get("price3");$hitxt="Pakke 3";
$fitcost	=$params->get("price4");$fittxt="Fitness Pakke";
$fee		=$params->get("memberfee");
?>
<style type="text/css">
	.box-temp #b-1{width:251px}
	.box-temp #b-2{width:353px}
	#m-table2 td.t-col-1{width:250px}
	.nohand{cursor:default}
</style>
<div class="wrapper">
	<div class="content clearfix" id="price-page">
	<ul class="breadcrumb mb20">
		<li><a class="nohand">Personlige oplysninger</a></li>
		<li class="active"><a>Dit abonnement</a></li>
		<li><a class="nohand">Book tid hos din vejleder</a></li>
		<li><a class="nohand">Kostvaner/ ønsker</a></li>
		<li><a class="nohand">Motionsvaner/ ønsker</a></li>
		
	</ul>
	<h1 class="hd">Vælg pakke og betal</h1>
	<form name="reg_form2" id="member-registration" action="index.php" method="post" class="form-validate clearfix" enctype="multipart/form-data">

	<div class="price-left">
	<?php
	$db->setQuery("SELECT * FROM #__content WHERE id=18");
	$row = $db->loadObject();
	?>
	<div class="col-box">

	<?php echo $row->introtext;?>
	</div>
	<div class="col-box">

	<div class="box-temp clearfix">
	<div id="b-1">
	<?php echo $row->fulltext;?>
	</div>
	<div id="b-2">
	<table id="m-table">
	<colgroup>
	<col id="ppack1">
	<col id="ppack2" style="background:#EEE">
	<col id="ppack3">
	<col id="ppack4">
	</colgroup>
	<tbody>
	<tr>
	<th>Slanke<br> Pakke 1</th>
	<th>Slanke<br> Pakke 2</th>
	<th>Slanke<br> Pakke 3</th>
	<th>Fitness<br> Pakke</th>
	</tr>
	<tr>
	<td>
	<a onclick="select_package(1)"><strong>Kr. <?php echo $lowcost?>,-</strong>
	<span>Pr. måned</span></a>
	</td>
	<td>
	<a onclick="select_package(2)"><strong>Kr. <?php echo $medcost?>,-</strong>
	<span>Pr. måned</span></a>
	</td>
	<td>
	<a onclick="select_package(3)"><strong>Kr. <?php echo $hicost?>,-</strong>
	<span>Pr. måned</span></a>
	</td>
	<td>
	<a onclick="select_package(4)"><strong>Kr. <?php echo $fitcost?>,-</strong>
	<span>Pr. måned</span></a>
	</td>
	</tr>
	</tbody></table>
	</div>
	</div>
	<table id="m-table2">
	<colgroup>
	<col>
	<col id="fpack1">
	<col id="fpack2">
	<col id="fpack3">
	<col id="fpack4">
	</colgroup>
	<tbody>
<?php
	$db->setQuery("SELECT a.*,
	(SELECT b.published FROM #__questions_core b WHERE a.title=b.title AND b.catid=11) published2,
	(SELECT c.published FROM #__questions_core c WHERE a.title=c.title AND c.catid=12) published3,
	(SELECT d.published FROM #__questions_core d WHERE a.title=d.title AND d.catid=16) published4
	FROM #__questions_core a
	WHERE catid=10");
	$rows = $db->loadObjectList();
	$i=0;
	?>
<?php
	foreach($rows as $row){
		//echo '<!--pre>',print_r($row),'</pre-->';
?>
		<tr <?php if($i) echo "class='even'"?>>

		<td class="t-col-1">
		<p>
		<a class="tip_trigger" href="#" title="">
		<img src="templates/fitplan/img/imgInfo.png" alt="">
		<span class="tip">
		<?php echo nl2br($row->text);?>
		<span class="arr-left"></span></span>
		</a>
		<?php echo $row->title;?>
		</p>
		</td>

		<td class="t-col-2">
<?php if($row->published == 1):?>
		<img src="templates/fitplan/img/imgCheck-1.png" alt="">
<?php endif;?>
		</td>

		<td class="t-col-3">
<?php if($row->published2 == 1):?>
		<img src="templates/fitplan/img/imgCheck-1.png" alt="">
<?php endif;?>
		</td>

		<td class="t-col-4">
<?php if($row->published3 == 1):?>
		<img src="templates/fitplan/img/imgCheck-1.png" alt="">
<?php endif;?>
		</td>

<td class="t-col-4">
<?php if($row->published4 == 1):?>
		<img src="templates/fitplan/img/imgCheck-1.png" alt="">
<?php endif;?>
		</td>
		</tr>
<?php
$i=1-$i;
	}?>

	<tr class="none">
	<td class="t-col-1 none"></td>
	<td class="t-col-2 none"><a class="bntBuynow" onclick="select_package(1)">Køb nu!</a></td>
	<td class="t-col-3 none"><a class="bntBuynow" onclick="select_package(2)">Køb nu!</a></td>
	<td class="t-col-4 none"><a class="bntBuynow" onclick="select_package(3)">Køb nu!</a></td>
	<td class="t-col-4 none"><a class="bntBuynow" onclick="select_package(4)">Køb nu!</a></td>
	</tr>

	</tbody></table>
	</div>
<?php /*?>
	<div class="col-box">
		<h1 class="c292929">Vælg tilkøb (valgfrit)</h1>
		<p class="p-pricetemp2">Vælg ekstra</p>
		<p id="p-pricetemp">Pris</p>
	<div class="clr"></div>
	<table id="m-table3">
	<tbody>
<?php
	$db->setQuery("SELECT * FROM #__questions_core WHERE catid=15");
	$rows = $db->loadObjectList();
	$i=0;$j=1;
	foreach($rows as $row){
		?>
		<tr <?php if($i) echo "class='even'"?>>
		<td class="t-col-5-">
		<p>
		<a href="#" title="" class="tip_trigger">
		<img src="templates/fitplan/img/imgInfo.png" alt="">
		<span class="tip">
		<?php echo nl2br($row->text);?>
		<span class="arr-left"></span></span>
		</a><?php echo $row->title;?></p>
		</td>

		<td class="t-col-6-">
		Kr. <?php echo $row->parent?>,-
		</td>

		<td class="t-col-7">
		<input type="checkbox" name="jform[options]" onclick="select_options(<?php echo $j?>)" value="<?php echo $row->parent?>">
		</td>
		</tr>
<?php
$i=1-$i;$j++;
	}?>



	</tbody></table>
	</div>
<?php */?>
	</div><!--.price-left-->

	<div class="price-right">
	<div class="box-right">
		<div class="box-hd clearfix">
		<h2>Min indkøbskurv</h2>
		<img src="templates/fitplan/img/imgInfo-1.png" alt="">
		</div>
		<div class="box-price-content">

		<p class="fl"><strong><span class="ca01b68"><?php echo $medtxt?></span></strong></p>
		<!--p class="fr"><span class="ca01b69">Kr. <?php //echo $medcost?>,-</span></p-->
		<div class="clear"></div>

		<div class="myShopcart clearfix">
			<div class="clearfix ceaeaea">
			<div class="fl">Medlemskab</div>
			<div class="fr ca01b70">Kr. <?php echo $medcost?>,-</div>
			</div>
		<div class="clearfix">
			<div class="fl">Opstartsgebyr *</div>
			<div class="fr">Kr. <?php echo $fee?>,-</div>
		</div>
<?php
	//make use last $rows
	$i=0;$j=1;
	foreach($rows as $row){
		?>
		<div class="clearfix <?php if(!$i) echo 'ceaeaea'?> hide opt<?php echo $j?>">
			<div class="fl" style="width:200px"><?php echo $row->title;?></div>
			<div class="fr">Kr. <?php echo $row->parent?>,-</div>
		</div>
<?php
$i=1-$i;$j++;
	}?>

<div class="clearfix bor-b">
	<div class="fl"><strong>Til betaling om 14 dage *</strong></div>
	<div class="fr"><strong class="ca01b71">Kr. <?php echo $medcost + $fee?>,-</strong></div>
</div>

		<div class="clearfix bor-b">
			<input type="checkbox" id="agreeterm" onclick="docalc()"/> <span id="agreetxt">Jeg har læst og accepteret</span> <a href="<?php echo JRoute::_('index.php?option=com_content&view=article&id=5&Itemid=104')?>" target="_blank" style="color:#3F48CC;text-decoration: underline;">abonnementsvilkår</a>
		</div>

		<div class="clearfix">
			<div>Indtast evt. rabatkode:</div>
			<input class="w167" name="jform[cp]" type="text">
		</div>

		<div class="clearfix mt15 mb10">
			<a class="bntCheckout" onclick="if(!$('#agreeterm').is(':checked')){$('#agreetxt').css('border','2px solid red');return false;}document.reg_form2.submit()">GÅ TIL BETALING</a>
		</div>
		</div>

		</div>
	</div><!--calc result-->
	<?php
	$db->setQuery("SELECT title, introtext text FROM `#__content` WHERE id IN(8,10)");
	$txt = $db->loadObjectList();
	?>
	<div class="box-right">
	<div class="box-hd clearfix">
	<h2>Opstartsgebyr</h2>
	<img src="templates/fitplan/img/imgInfo-2.png" alt="">
	</div>
	<div class="box-price-content">
	<?php echo $txt[1]->text?>
	</div>
	</div>
<?php /*?>
	<div class="box-right">
	<div class="box-hd clearfix">
	<h2>Kundeservice</h2>
	<img src="templates/fitplan/img/imgInfo-3.png" alt="">
	</div>
	<div class="box-price-content">
	<?php echo $txt[0]->text?>
	</div>
	</div>
<?php */?>
	</div>

<input type="hidden" name="jform[basecost]" value=<?php echo $medcost?> />
<input type="hidden" name="jform[no]" value=2 />
<input type="hidden" name="jform[options_nam]" id="options_nam" value="" />
<input type="hidden" name="jform[total_nam]" id="total_nam" value="<?php echo $medcost + $fee?>" />

<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration.step5" />
<?php echo JHtml::_('form.token');?>
	</form>

	<a class="fl bntPrevious" href="index.php?option=com_users&view=registration">Forrige</a>
	</div>
</div>
<script type="text/javascript">
var mark=2;
function getbyname(n){
	return document.reg_form2.elements[n];
}

function select_package(no){
	var txt, cost;
	if(!no)
		return;
	switch(no){
	case 1:
	$(".ca01b68")
	cost=<?php echo $lowcost?>;		txt="<?php echo $lowtxt?>";
	break;
	case 2:
	cost=<?php echo $medcost?>;		txt="<?php echo $medtxt?>";
	break;
	case 3:
	cost=<?php echo $hicost?>;		txt="<?php echo $hitxt?>";
	break;
	case 4:
	cost=<?php echo $fitcost?>;		txt="<?php echo $fittxt?>";
	break;
	}
	$("#ppack"+no).css("background", "#EEE");
	if(mark){
		$("#ppack"+mark).css("background", "transparent");
	}
	mark=no;
	$(".ca01b68").html(txt);
	$(".ca01b69").html('Kr. '+cost+',-');
	getbyname("jform[basecost]").value=cost;
	getbyname("jform[no]").value=no;
	docalc();
}
/*function select_time(x){
	getbyname("jform[length]").value=x;
	docalc();
}*/
function select_options(no){
	if(!no)
		return;
	selectedoptions=[];
	indexoptions=[];
	$("input[name='jform[options]']").each(function(i){
	if($(this).is(":checked")){
		indexoptions.push(i+1);
		selectedoptions.push(parseInt($(this).val()));
		$(".opt"+no).show();
	}else
		$(".opt"+(i+1)).hide();
	$('#options_nam').val(indexoptions);
	});
	docalc();
}
function docalc(){
	var base		=getbyname("jform[basecost]").value;
	var course	=1;//getbyname("jform[length]").value;
	var fee		=<?php echo $fee?>;
	cost=base*course;//cost with discount
	/*if(course==3)
	cost-=48;
	else if(course==6)
	cost-=295;
*/
	options=0;//opts calculation
	try{
	$.each(selectedoptions,function(i,v){
	options+=v;
	})
	}catch(ex){}
	//console.log( options);
	total=cost+options;
	total+=fee;

	$(".ca01b70").html("Kr. "+cost+",-");
	$(".ca01b71").html("Kr. "+total+",-");
	$("#total_nam").attr('value', total);
}
</script>
